package com.example.user.demo1;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;

import java.util.List;

public class CustomedPopu extends PopupWindow {

    Context context;
    List<String> list;
    ListView listView;
    CallBack callBack;

    public CustomedPopu(Context context, List<String> list, CallBack callBack) {
        this.context = context;
        this.list = list;
        this.callBack =callBack;
        initView();
    }

    private void initView(){

        View view = LayoutInflater.from(context).inflate(R.layout.popu_layout,null);
        listView = view.findViewById(R.id.list_view);
        Adapter adapter = new Adapter(context,list);
        listView.setAdapter(adapter);
        this.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
        this.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        setContentView(view);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                if (callBack != null){
                    callBack.click(position);
                    dismiss();
                }
            }
        });


    }




}
